package imp.core.data;

import imp.core.basics.ErrorHandler;
import imp.core.basics.IOManager;
import imp.core.data.configuration.FilePaths;
import imp.core.debug.DebugManager;


/**
 * The class administers the path data (the program path and song path).
 * @author Patrick Arnold
 * @since 08.09.2010
 *
 */
public class PathData implements FilePaths {
	
	/** The program path which specifies the program directory. */
	private static String programpath;
	
	/** The song path which specifies the song directory containing the songs. */
	private static String songpath;
	
	
	/**
	 * Loads the path data.
	 * @return Specifies whether loading the path data has been successful or not.
	 */
	public static boolean loadData() {
		
		String path = PATHS;
		String[] file = IOManager.loadFile( path);
		
		String message = "";
		
		
		// Error handling:
		
		if( file == null) {   // General IO-Error 
			return false;
		} else {
			if( file.length < 2) {   // Missing arguments
				message = "Invalid number of arguments in Path.dat. Expected 2, found " 
					+ file.length + ".";
				String location = ErrorHandler.getParserLocation();
				ErrorHandler.error( message, location, null);
				return false;
			} else {
				if( (file[0].length() == 0) || (file[1].length() == 0)) {   // Blank lines
					message = "Blank lines in Path.dat.";
					String location = ErrorHandler.getParserLocation();
					ErrorHandler.error( message, location, null);
					return false;
				}
			}
		}
		
		
		programpath = file[0];
		songpath = file[1];	
		

		if( SessionData.isDebugMode()) {
			String[] output = new String[4];
			output[0] = "Runtime:        [" + SessionData.getCurrentRuntime() + " ms]";
			output[1] = "";
			output[2] = "Program path:   " + programpath;
			output[3] = "Program path:   " + songpath;
			DebugManager.displayStringField( output, "Path Data");
		}
		
		
		return true;
		
	}
	
	
	
	/**
	 * Returns the program directory path.
	 * @return The program directory path that specifies the program directory.
	 */
	public static String getProgrampath() {
		return programpath;
	}
	
	
	/**
	 * Returns the song directory path.
	 * @return The song directory path that specifies the song directory.
	 */
	public static String getSongpath() {
		return songpath;
	}
	
	
}